var app = getApp()
import regeneratorRuntime from '../../../utils/runtime.js';
import img_list from '../../../utils/util.js';
import { getData, setData, clearData, dataKey } from '../../../utils/storage.js';
import {
  queryAll,
  cancelCollect,
} from '../../../utils/imapi.js';
Page({

  data: {
    list: [],
    is_edit:false,
    show_title:false,
    bgColor:'white',
    show: 1,
    selectAll: 0,
    total_money: 0,
    startX: 0, //开始坐标
    startY: 0,
    productList:[
      {
        commission_price: 0,
        commission_rate: 0,
        coupon_end_time: "1590376223000",
        coupon_id: "",
        coupon_info: "",
        coupon_price: 70,
        coupon_remain_count: 0,
        coupon_start_time: "1591801199000",
        coupon_total_count: 0,
        coupon_url: "http://coupon.m.jd.com/coupons/show.action?key=958d27fe47f147578d8de646007ea174&roleId=31655293",
        item_id: "67999874797",
        item_url: "item.jd.com/67999874797.html",
        p: "JD",
        pict_main_url: "http://img14.360buyimg.com/ads/jfs/t1/119285/38/2019/222325/5e9d9a35Ead59b235/199aa87383978cfd.jpg",
        pict_thumimg: "",
        price: 138,
        shop_id: "",
        shop_name: "",
        shop_score: "",
        short_title: "",
        small_images: (7) ["http://img14.360buyimg.com/ads/jfs/t1/119285/38/2019/222325/5e9d9a35Ead59b235/199aa87383978cfd.jpg", "http://img14.360buyimg.com/ads/jfs/t1/105071/26/19248/444733/5e9d98b9E2df4ad2e/0b99c36c41f57c31.jpg", "http://img14.360buyimg.com/ads/jfs/t1/116024/22/3354/176873/5ea791d2E2b5d4886/d69b4e854fc2338c.jpg", "http://img14.360buyimg.com/ads/jfs/t1/114124/13/3359/144798/5ea791d2E80afdaf8/3aa1bf2c9b9b31d8.jpg", "http://img14.360buyimg.com/ads/jfs/t1/91701/25/18292/254411/5e951682E9a904614/16ae73460eaa145f.jpg", "http://img14.360buyimg.com/ads/jfs/t1/100863/22/18638/241590/5e951682E2774d8ab/55c396c7c0d8ee10.jpg", "http://img14.360buyimg.com/ads/jfs/t1/117112/33/1074/183045/5e951682Ea4719b44/cf4a130dd850aa0e.jpg"],
        suggest_description: "",
        thirty_days_total_sales_volume: 11164,
        title: "恒源祥polo衫男士短袖t恤男装翻领中青年体恤衫2020夏季新款男装上衣 蓝色 175",
        zk_price: 0,
      },
      {
        commission_price: 0,
        commission_rate: 0,
        coupon_end_time: "1590376223000",
        coupon_id: "",
        coupon_info: "",
        coupon_price: 70,
        coupon_remain_count: 0,
        coupon_start_time: "1591801199000",
        coupon_total_count: 0,
        coupon_url: "http://coupon.m.jd.com/coupons/show.action?key=958d27fe47f147578d8de646007ea174&roleId=31655293",
        item_id: "67999874797",
        item_url: "item.jd.com/67999874797.html",
        p: "JD",
        pict_main_url: "http://img14.360buyimg.com/ads/jfs/t1/119285/38/2019/222325/5e9d9a35Ead59b235/199aa87383978cfd.jpg",
        pict_thumimg: "",
        price: 138,
        shop_id: "",
        shop_name: "",
        shop_score: "",
        short_title: "",
        small_images: (7) ["http://img14.360buyimg.com/ads/jfs/t1/119285/38/2019/222325/5e9d9a35Ead59b235/199aa87383978cfd.jpg", "http://img14.360buyimg.com/ads/jfs/t1/105071/26/19248/444733/5e9d98b9E2df4ad2e/0b99c36c41f57c31.jpg", "http://img14.360buyimg.com/ads/jfs/t1/116024/22/3354/176873/5ea791d2E2b5d4886/d69b4e854fc2338c.jpg", "http://img14.360buyimg.com/ads/jfs/t1/114124/13/3359/144798/5ea791d2E80afdaf8/3aa1bf2c9b9b31d8.jpg", "http://img14.360buyimg.com/ads/jfs/t1/91701/25/18292/254411/5e951682E9a904614/16ae73460eaa145f.jpg", "http://img14.360buyimg.com/ads/jfs/t1/100863/22/18638/241590/5e951682E2774d8ab/55c396c7c0d8ee10.jpg", "http://img14.360buyimg.com/ads/jfs/t1/117112/33/1074/183045/5e951682Ea4719b44/cf4a130dd850aa0e.jpg"],
        suggest_description: "",
        thirty_days_total_sales_volume: 11164,
        title: "恒源祥polo衫男士短袖t恤男装翻领中青年体恤衫2020夏季新款男装上衣 蓝色 175",
        zk_price: 0,
      },
    ],
    is_iphoneX:app.globalData.isIphonex,
    img_list:"img_list.img_list"
  },

  onLoad: async function (options) {
    this.setData({
      img_list:img_list.img_list
    })
    var that = this;
    const {data} = await queryAll({
      user_id:app.globalData.uid,
      
    })
  },
  showEidt(){
    this.setData({
      is_edit:!this.data.is_edit
    })
  },
  chooseAll() {
    this.data.selectAll = !this.data.selectAll
    let total_money = 0;
    if (this.data.selectAll) {
      this.data.productList.forEach(item => {
        item.is_select = 1;
      })
      this.setData({
        productList: this.data.productList,
        selectAll: 1,
        total_money,
      })
    } else {
      this.data.productList.forEach(item => {
        item.is_select = 0;
      })
      this.setData({
        productList: this.data.productList,
        selectAll: 0
      })
    }
  },
  onchange(e){
    console.log(e)
    var index = e.detail.index;
    this.data.productList[index].is_select = !this.data.productList[index].is_select;
    var allSeleted = true
    this.data.productList.forEach((item, idx) => {
      if (!item.is_select) {
        allSeleted = false
      }
    })
    this.setData({
      selectAll: allSeleted,
      productList:this.data.productList
    })
  },

  //删除事件

  remove: function (e) {
    let that = this;
    let list = that.data.productList;
    wx.showModal({
      title: '温馨提示',
      content: '是否删除选中商品',
      success: function (res) {
        if (res.confirm) {
          var new_arr = []
          that.data.productList.forEach(item => {
            if (!item.is_select) {
              new_arr.push(item)
            }
          })
          that.setData({
            is_edit:false,
            productList: new_arr,
          })
        }
      }
    })
  },

  // 下拉加载
  onPullDownRefresh: function () {
    var that = this;
    // wx.showNavigationBarLoading();
    setTimeout(() => {
      wx.stopPullDownRefresh();
      // wx.hideNavigationBarLoading();
    }, 500);
    var url = 'api/shopCart/getCartProductInfoByMember';
    var data = {};
    req.get(that, url, data, (res) => {
      let data = res.data.data;
      that.setData({
        list: data,
      })
    })
  },

})